package cn.edu.njust.controller;

import cn.edu.njust.core.enums.SignInStatusEnum;
import cn.edu.njust.pojo.bo.PageBean;
import cn.edu.njust.pojo.bo.RestResult;
import cn.edu.njust.pojo.dto.IdDTO;
import cn.edu.njust.pojo.dto.PageParamDTO;
import cn.edu.njust.pojo.dto.PageQueryDTO;
import cn.edu.njust.pojo.po.Leaves;
import cn.edu.njust.pojo.po.User;
import cn.edu.njust.service.LeaveService;
import cn.edu.njust.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



@Tag(name = "辅导员管理接口")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/counselor")
public class CounselorController {

    private final UserService userService;

    private final LeaveService leaveService;

    /**
     * 请假列表
     *
     * @param pageParam 分页查询参数
     */
    @Operation(summary = "请假列表")
    @PostMapping(value = "/selectStudentInLeaves")
    public RestResult<PageBean<Leaves>> selectStudentInLeaves(@RequestBody PageParamDTO pageParam) {
        PageBean<Leaves> leavesPageBean = leaveService.pageQueryList(pageParam.getPageNum(), pageParam.getPageSize());
        return RestResult.success(leavesPageBean);
    }

    /**
     * 分页条件查询
     *
     * @param pageQuery 查询参数
     */
    @Operation(summary = "分页条件查询")
    @PostMapping("/selectByPageAndCondition")
    public RestResult<PageBean<User>> selectByPageAndCondition(@RequestBody PageQueryDTO pageQuery) {
        PageBean<User> pageBean = userService.selectByPageAndCondition(pageQuery.getPageNum(), pageQuery.getPageSize(), pageQuery.getUser());
        return RestResult.success(pageBean);
    }

    /**
     * 同意请假
     *
     * @param id 学生id
     */
    @Operation(summary = "同意请假")
    @PostMapping("/agreeLeaveRequest")
    public RestResult<Void> agreeLeaveRequest(@RequestBody IdDTO id) {
        userService.updateSignInStatusById(id.getId(), SignInStatusEnum.SIGNED);
        return RestResult.success();
    }

    /**
     * 拒绝请假
     *
     * @param id 学生id
     */
    @Operation(summary = "拒绝请假")
    @PostMapping("/disAgreeLeaveRequest")
    public RestResult<Void> disAgreeLeaveRequest(@RequestBody IdDTO id) {
        userService.updateSignInStatusById(id.getId(), SignInStatusEnum.UNSIGNED);
        return RestResult.success();
    }
}
